home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / memory / xms200je / doserror.h < prev    next >
C/C++ Source or Header  |  1993-11-22  |  3KB  |  67 lines

  1. //--------------------------------------------------------------------------
  2. //
  3. //      DOSERROR.H: header file for DOS critical error/ctrl-break handler.
  4. //      Copyright (c) J.English 1993.
  5. //      Author's address: je@unix.brighton.ac.uk
  6. //
  7. //      Permission is granted to use copy and distribute the
  8. //      information contained in this file provided that this
  9. //      copyright notice is retained intact and that any software
  10. //      or other document incorporating this file or parts thereof
  11. //      makes the source code for the library of which this file
  12. //      is a part freely available.
  13. //
  14. //--------------------------------------------------------------------------
  15. //
  16. //      Revision history:
  17. //      2.0     Nov 1993        This file added to provide error handling
  18. //                              facilities
  19. //
  20. //--------------------------------------------------------------------------
  21.  
  22. #ifndef __DOSERROR_H
  23. #define __DOSERROR_H
  24.  
  25. #include <stdlib.h>
  26.  
  27. //--------------------------------------------------------------------------
  28. //
  29. //      Class DOSerror.
  30. //
  31. //      Instances of this class (or derivations thereof) intercept critical
  32. //      errors and control-break interrupts to prevent programs from being
  33. //      unceremoniously terminated.  The default action is to return an
  34. //      automatic FAIL response to critical errors and to ignore control-
  35. //      break events.  Derived classes can overload the member functions
  36. //      "criticalError" and "controlBreak" as desired to provide more
  37. //      application-specific functionality.  Instances may be nested if
  38. //      desired; the most recently-declared instance will intercept all
  39. //      critical errors and control-break events.
  40. //
  41. class DOSerror
  42. {
  43.     typedef void interrupt (*Handler) (...);
  44.  
  45.   public:
  46.     DOSerror ();                        // install an error handler
  47.     virtual ~DOSerror ();               // uninstall handler
  48.  
  49.   protected:
  50.     enum    error                       { IGNORE = 0, RETRY = 1, FAIL = 3 };
  51.     virtual error criticalError (int)   { return FAIL; }
  52.     virtual void  controlBreak  ()      { }
  53.  
  54.   private:
  55.     void*  operator new (size_t)        { return 0; }
  56.                                         // ... to prevent heap allocation
  57.     static void interrupt CtrlBreak     ();
  58.     static void interrupt Critical      (unsigned, unsigned di, unsigned,
  59.                                          unsigned, unsigned,    unsigned,
  60.                                          unsigned, unsigned,    unsigned ax);
  61.     DOSerror* oldInstance;
  62.     Handler   oldCtrlBreak;
  63.     Handler   oldCritical;
  64. };
  65.  
  66. #endif
  67.